<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>设置我的资料</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <script src="${global_templets_skin}/aceeditor/build/src/ace.js"></script>
    <script src="${global_templets_skin}/aceeditor/build/src/ext-language_tools.js"></script>
    <script src="${global_templets_skin}/aceeditor/build/src/theme-eclipse.js"></script>
    <link rel="stylesheet" href="${global_templets_skin}/systemstyle/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="${global_templets_skin}/systemstyle/style/admin.css" media="all">
</head>
<body>

<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-header">添加模板详细页面</div>
                <div class="layui-card-body">

                    <form class="layui-form" lay-filter="" pad15>
                        <div class="layui-form-item">
                            <label class="layui-form-label">所属模型</label>
                            <div class="layui-input-inline">
                                <select name="moduleId" lay-filter="moduleId" lay-verify="required" lay-search="">
                                    <option value="">请选择该栏目使用的模型</option>
                                    <option value="0"<#if template.moduleId == 0> selected = "selected"</#if>>网站首页</option>
                                    <#list modulelist as list>
                                    <option value="${list.id!}"<#if list.id==template.moduleId> selected = "selected"</#if>>${list.moduleName!}</option>
                                    </#list>
                                </select>
                            </div>
                            <div class="layui-form-mid layui-word-aux">不可修改。一般用于后台登入名</div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">模板类型</label>
                            <div class="layui-input-inline">
                                <select name="pageType" lay-filter="pageType" lay-verify="required" lay-search="">
                                    <option value="">请选择该模板类型</option>
                                    <option value="0"<#if template.pageType == 0> selected = "selected"</#if>>首页模板</option>
                                    <option value="1"<#if template.pageType == 1> selected = "selected"</#if>>频道封面模板</option>
                                    <option value="2"<#if template.pageType == 2> selected = "selected"</#if>>列表模板</option>
                                    <option value="3"<#if template.pageType == 3> selected = "selected"</#if>>内容页面模板</option>
                                    <option value="4"<#if template.pageType == 4> selected = "selected"</#if>>单独页面模板</option>
                                </select>
                            </div>
                            <div class="layui-form-mid layui-word-aux">模板类型，比如：频道首页模板或者内容页面模板</div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">模板名称</label>
                            <div class="layui-input-inline">
                                <input type="text" name="templateName" value="${template.templateName!}" lay-verify="required" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item layui-form-text">
                            <label class="layui-form-label">模板编辑</label>
                            <div class="layui-input-block">
                                <pre id="editor">${template.templatePage}</pre>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">模板说明</label>
                            <div class="layui-input-block">
                                <textarea name="remark" placeholder="请输入内容" class="layui-textarea">${template.remark!}</textarea>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <div class="layui-input-block">
                                <input type="hidden" name="id" id="id" value="${templateId!}">
                                <button class="layui-btn" lay-submit lay-filter="setTemplatePage">确认修改</button>
                                <button type="reset" class="layui-btn layui-btn-primary reset">重新填写</button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
<script src="${global_templets_skin}/systemstyle/layui/layui.js"></script>
<script>
    layui.config({
        base: '${global_templets_skin}/systemstyle/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'set','form'], function () {
        var form   = layui.form;
        var $      = layui.jquery;
        var layer  = layui.layer;

        ace.require("ace/ext/language_tools");
        var editor = ace.edit("editor");
        editor.$blockScrolling = Infinity;
        editor.setFontSize(16);
        editor.getSession().setMode("ace/mode/html");//设置程序语言
        editor.getSession().setTabSize(4);
        editor.getSession().setUseWrapMode(false);
        editor.setHighlightActiveLine(false);
        editor.setOptions({
            enableBasicAutocompletion: true,
            enableSnippets: true,
            enableLiveAutocompletion: true
        });
        editor.setTheme("ace/theme/eclipse");

        form.on('submit(setTemplatePage)', function(data) {
            /*if (editor.getValue() == "" || editor.getValue().length() < 20 ) {
                layer.msg("模板内容不得为空或者小于20个字符", {icon: 2});
                return false;
            }*/
            data.field.templatePage=editor.getValue();
            $.ajax({
                url:'/admin/template/page/edit.do',
                type:'post',
                dataType: 'json',
                data: data.field,
                success:function(e){
                    if (e.code == "0") {
                        layer.msg('成功');
                        window.location.reload();
                    }else {
                        layer.msg(e.message, {icon: 2});
                    }
                }
            })
            //防止页面跳转
            return false;
        });
    });
</script>

</body>
</html>